#include "SingleSliderWidget.h"
#include "matrixstack.h"


SingleSliderWidget::SingleSliderWidget(QWidget *parent, MatrixStack &mtxStack)
: WidgetWithMatrix(parent),
  m_mtxStack(mtxStack)
{
	m_ss.setupUi(this);
	connect(m_ss.value, SIGNAL(valueChanged(int)), this, SLOT(onTrackbarValueChanged(int)));
	connect(m_ss.upBtn, SIGNAL(clicked()), this, SLOT(upButtonClicked()));
	connect(m_ss.downBtn, SIGNAL(clicked()), this, SLOT(downButtonClicked()));

	m_mtxId = m_mtxStack.pushMatrix();
}

SingleSliderWidget::~SingleSliderWidget()
{
}

void SingleSliderWidget::onTrackbarValueChanged(int value)
{
	valueChanged(value);
	updateMatrixStack();
}

void SingleSliderWidget::setSliderRange(int min, int max)
{
	m_ss.value->setRange(min, max);
}

void SingleSliderWidget::setCaption(const QString &caption)
{
	m_ss.label->setText(caption);
}

void SingleSliderWidget::upButtonClicked()
{
	bool success = m_mtxStack.moveMatrixUp(m_mtxId);

	if ( success )
	{
		// send some update request to gui
	}
}

void SingleSliderWidget::downButtonClicked()
{
	bool success = m_mtxStack.moveMatrixDown(m_mtxId);

	if ( success )
	{
		// send some update request to gui
	}
}

Matrix &SingleSliderWidget::matrix() 
{ 
	return m_mtxStack.getMatrix(m_mtxId); 
}

void SingleSliderWidget::updateMatrixStack()
{
	m_mtxStack.updateResultMtx();
}

